package top.yokey.android.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatRadioButton;
import androidx.appcompat.widget.AppCompatTextView;

import top.yokey.android.R;
import top.yokey.android.base.BaseActivity;
import top.yokey.android.http.BaseCallBack;
import top.yokey.android.http.HttpHelp;

public class ModifyGenderActivity extends BaseActivity {

    private AppCompatImageView backImageView;
    private AppCompatRadioButton manRadioButton;
    private AppCompatRadioButton womanRadioButton;
    private AppCompatTextView modifyTextView;
    private View newGenderView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_modify_gender);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initView() {
        backImageView = findViewById(R.id.backImageView);
        modifyTextView = findViewById(R.id.modifyTextView);
        manRadioButton = findViewById(R.id.manRadioButton);
        womanRadioButton = findViewById(R.id.womanRadioButton);
        newGenderView = findViewById(R.id.newGenderView);
    }

    @Override
    public void initEvent() {

        backImageView.setOnClickListener(view -> finish());

        manRadioButton.setOnClickListener(view -> {
            if (manRadioButton.isChecked()) {
                womanRadioButton.setChecked(false);
            }
        });

        womanRadioButton.setOnClickListener(view -> {
            if (womanRadioButton.isChecked()) {
                manRadioButton.setChecked(false);
            }
        });

        modifyTextView.setOnClickListener(view -> {
            modifyTextView.setEnabled(false);
            modifyTextView.setText("正在修改...");
            HttpHelp.get().ready("member", "modifyGender")
                    .add("gender", manRadioButton.isChecked() ? "1" : "2")
                    .get(new BaseCallBack() {
                        @Override
                        public void onSuccess(String data) {
                            Toast.makeText(ModifyGenderActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                            finish();
                        }

                        @Override
                        public void onFailure(String reason) {
                            Toast.makeText(ModifyGenderActivity.this, reason, Toast.LENGTH_SHORT).show();
                            modifyTextView.setEnabled(true);
                            modifyTextView.setText("修改性别");
                        }
                    });

        });
    }
}
